package au.com.iglootech.TaxTimeToolTip.ui.payment;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import au.com.iglootech.TaxTimeToolTip.Entity.Company;
import au.com.iglootech.TaxTimeToolTip.Entity.Invoice;
import au.com.iglootech.TaxTimeToolTip.Entity.Task;
import au.com.iglootech.TaxTimeToolTip.dao.GenericDao;
import au.com.iglootech.component.IGTTable;

import com.vaadin.data.util.BeanContainer;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.Window;
@Configurable(preConstruction = true)
@Component
@Scope("request")
public class InvoiceDetailsWindow extends Window {
	private static final String COMPANY_NAME = "company.companyName";
	private BeanContainer<String, Task> beans;
	private Invoice invoice;
	
	@Autowired
	private transient GenericDao genericDao;
	
	public InvoiceDetailsWindow(Invoice invoice)
	{
		this.invoice = invoice;
		setCaption("Invoice Details");
		setModal(true);
		setWidth("550px");
		setHeight("500px");
		beans = new BeanContainer<String, Task>(Task.class);
		beans.setBeanIdProperty("key");
		beans.addNestedContainerProperty(COMPANY_NAME);
		
		initContent();
	}
	
	private void initContent()
	{
		Panel panel = new Panel();
		IGTTable taskTable = new IGTTable("Task List", beans);
		taskTable.setColumnHeader(COMPANY_NAME, "Company");
		taskTable.setWidth("100%");
		taskTable.setHeight("300px");
		taskTable.setVisibleColumns(new String[] {"taskName",
				COMPANY_NAME, "period", "unit", "startDate" });
		List<Task> result = new ArrayList<Task>(genericDao.findByKeys(Task.class, invoice.getTaskSets()));
		beans.removeAllItems();
		for (Task task : result) {
			beans.addBean(task);
		}
		panel.addComponent(taskTable);
		//
		TextArea details = new TextArea("Details");
		details.setWidth("100%");
		details.setHeight("50px");
		details.setValue(invoice.getDetails());
		panel.addComponent(details);
		addComponent(panel);
	}
}
